package com.sunbird.crm.servce.impl;

import com.sunbird.crm.base.Vo.RestMessage;
import com.sunbird.crm.dao.sys.TMeunMapper;
import com.sunbird.crm.entity.sys.TMeun;
import com.sunbird.crm.servce.SysMeunService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @ClassName SysMeunServiceImpl
 * @Descriptiom TODO
 * @Author Sunbird
 * @Date 2019/9/4 22:24
 * @Version 1.0
 **/
@Service
public class SysMeunServiceImpl implements SysMeunService {

    @Autowired
    private TMeunMapper meunMapper;

    /**
     * @Author Sunbird
     * @Description 新增目录树
     * @Date  2019/9/4
     * @Param
     * @return
     **/

    @Override
    public RestMessage save(TMeun meun) {
        RestMessage message = new RestMessage();
        int count= meunMapper.insert(meun);
        if (count>0){
            message.setMsg_code(200);
            message.setMsg("新增成功");
        }else {
            message.setMsg_code(500);
            message.setMsg("新增失败");
        }
        return  message;
    }

    /**
     * @Author Sunbird
     * @Description //TODO  根据用户角色查询权限菜单
     * @Date   2019/9/4
     * @Param
     * @return
     **/
    @Override
    public RestMessage find(String meunCode) {
        RestMessage message =new RestMessage();
        TMeun meun = meunMapper.selectByPrimaryKey(meunCode);
        if (meun.getMenuCode()!= null){
            List<TMeun> list = new ArrayList<TMeun>();
            list.add(meun);
            message.setMsg_list(Collections.singletonList(list));
        }
        return message;
    }
}
